package com.swind.fast.common.context;

import com.swind.fast.common.constant.CommonConstant;
// import com.swind.cloud.security.common.util.StringHelper;
// import org.junit.Test;
// import org.junit.runner.RunWith;
// import org.mockito.runners.MockitoJUnitRunner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

// import static org.junit.Assert.assertEquals;

public class BaseContextHandler {

    public static ThreadLocal<Map<String, Object>> threadLocal = new ThreadLocal<Map<String, Object>>();

    public static void set(String key, Object value) {
        Map<String, Object> map = threadLocal.get();
        if (map == null) {
            map = new HashMap<String, Object>();
            threadLocal.set(map);
        }
        map.put(key, value);
    }

    public static Object get(String key){
        Map<String, Object> map = threadLocal.get();
        if (map == null) {
            map = new HashMap<String, Object>();
            threadLocal.set(map);
        }
        return map.get(key);
    }

    public static String getAppCode() {
        Object value = get(CommonConstant.FRONT_APP_CODE);
        return returnObjectValue(value);
    }

    public static void setAppCode(String appCode){
        set(CommonConstant.FRONT_APP_CODE, appCode);
    }

    private static String returnObjectValue(Object value) {
        return value==null?null:value.toString();
    }

}
